﻿$(document).ready(function () {
	var $txtRate = $("#txtRate").kendoNumericTextBox({
		min: 0,
		max: 10,
		step: 0.5,
		value: 10
	}).data("kendoNumericTextBox");

	$("#btnSaveRate").click(function () {
		saveRate($txtRate.value());
	});

	$txtRate.enable(false);

	$("#rateRestaurantWindow").data("kendoWindow").center();

	if (getCurrReserve().State == 'Confirmada') {
		$("#divCantRateMessage").hide();
		$txtRate.enable(true);
		$("#btnSaveRate").removeAttr('disabled');
	}

});

function saveRate(value) {
	$.ajax({
		type: "POST",
		url: "Customer/rateRestaurant",
		contentType: "application/json; charset=utf-8",
		data: JSON.stringify({
			reserve: getCurrReserve(),
			points: value
		}),
		success: function () {
			alert("Se califico correctamente el restaurante");

			$("#rateRestaurantWindow").data("kendoWindow").close();
		},
		error: function (xhr, ajaxOptions, thrownError) {
			document.write(xhr.responseText);
		}
	});
}